
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 02/18/2010 14:20:32
-- Generated from EDMX file: D:\Demos\Foundation\AhisDemoSolution\Ahis.Demo.Backend\AhisModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [AhisDemoDb];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------


-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------


-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'FlightSet'
CREATE TABLE [dbo].[FlightSet] (
    [FlightNr] nvarchar(10)  NOT NULL,
    [From] nvarchar(max)  NOT NULL,
    [To] nvarchar(max)  NOT NULL,
    [MaxPassengers] smallint  NOT NULL
);
GO

-- Creating table 'PassengerSet'
CREATE TABLE [dbo].[PassengerSet] (
    [Id] uniqueidentifier  NOT NULL,
    [Firstname] nvarchar(max)  NOT NULL,
    [Lastname] nvarchar(max)  NOT NULL,
    [Flight_FlightNr] nvarchar(10)  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [FlightNr] in table 'FlightSet'
ALTER TABLE [dbo].[FlightSet]
ADD CONSTRAINT [PK_FlightSet]
    PRIMARY KEY CLUSTERED ([FlightNr] ASC);
GO

-- Creating primary key on [Id] in table 'PassengerSet'
ALTER TABLE [dbo].[PassengerSet]
ADD CONSTRAINT [PK_PassengerSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Flight_FlightNr] in table 'PassengerSet'
ALTER TABLE [dbo].[PassengerSet]
ADD CONSTRAINT [FK_FlightPassenger]
    FOREIGN KEY ([Flight_FlightNr])
    REFERENCES [dbo].[FlightSet]
        ([FlightNr])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_FlightPassenger'
CREATE INDEX [IX_FK_FlightPassenger]
ON [dbo].[PassengerSet]
    ([Flight_FlightNr]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------